<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="jakarta.tags.core" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>主页</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 0;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: flex-start;
            height: 100vh;
        }
        h1 {
            text-align: center;
            color: #333;
        }
        table {
            width: 60%;
            border-collapse: collapse;
            margin-top: 10px;
        }
        th, td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: left;
        }
        th {
            background-color: #f2f2f2;
            color: #333;
        }
    </style>
</head>
<body>
<h2>${sessionScope.username}，欢迎您！</h2>
<h1>注册用户信息</h1>
<!-- 添加搜索表单 -->
<form action="home" method="GET">
    <input type="text" name="searchKeyword" placeholder="输入用户名或电话进行搜索" />
    <button type="submit">搜索</button>
</form>
<h5>${msg}</h5>
<table>
    <thead>
    <tr>
        <th>编号</th>
        <th>姓名</th>
        <th>密码</th>
        <th>性别</th>
        <th>电话</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <%--遍历user数组--%>
    <c:forEach items="${users}" var="user" varStatus="status">
        <%-- 计算当前页的第一个编号 --%>

        <tr>
            <td>${firstItemIndex + status.index}</td> <!-- 使用计算后的编号 -->
            <td>${user.username}</td>
            <td>${user.password}</td>
            <td>${user.gender}</td>
            <td>${user.phone}</td>
            <td>
                <a href="/lession8_ed_war/edit?id=${user.id}">编辑</a>
                <a href="/lession8_ed_war/delete?id=${user.id}">删除</a>
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>
<div>
    <!-- 分页导航 -->
    <c:forEach begin="1" end="${totalPages}" var="i">
        <a href="home?pageIndex=${i}&searchKeyword=${searchKeyword}">第${i}页</a>
    </c:forEach>
</div>
</body>
</html>